#!/usr/local/bin/python
# -*- coding: utf-8 -*-

import datetime
from flask import Flask, url_for, request, session, render_template, redirect
from flaskext.sqlalchemy import SQLAlchemy
from json import dumps

from bompy import app
from utils import q, table, login_required, get2parameters, formtable, textinput, unitoptions, designoptions, typeoptions
from model import Design, BOM, Production_Capacity, Production_Week, Receipt_Order, Order, Extern

db = SQLAlchemy(app)

@app.route('/vieworders')
@login_required
def vieworders():
    t = table(["Year","Week","Provider","Design ID","Description","Quantity"])
    return render_template("vieworders.html",t=t)


@app.route('/_order_search')
@login_required
def order_search():
    d={"aaData":[]}
    for o in Order.query.all():
        l=[o.Year,
        o.Week_ISO,
        Extern.query.filter_by(ID_Extern=o.ID_Extern).first().Name,
        o.ID_Design,
        Design.getCurrent(o.ID_Design).Description_Std,
        o.Quantity]
        d["aaData"].append(l)
    return dumps(d)    
    
    
    
    
    
    
    
    
    
    
